using System;
using System.Collections.Generic;
using System.Text;
using TVProgram.Base;
using System.Net;
using System.IO;
using System.Globalization;

namespace TVProgram.Channels
{
    class HTV : BaseChannel
    {
        public HTV( DateTime CurDay, string channel)
        {
            string channelid = "";
            if (channel.CompareTo("8") == 0)
                channelid = "9";
            else
                channelid = "7";

            this._name = "HTV" + channelid;
            this._date = CurDay;
            string Day = Convert.ToString(this._date.Day);
            string Month = Convert.ToString(this._date.Month);
            string Year = Convert.ToString(this._date.Year);
            this._url = "http://www.htv.com.vn/chuongtrinh/default.asp?channel_id=" + channel +"&date=" + Day +"-" + Month + "-" + Year+"#lps";
        }

        public override void GetTextFromHtml(string html)
        {

            string stra = "<td class=\"tdFormRow\" align=\"center\">";
            string str1 = "align=\"center\">";
            string str2 = "</td>";
            int curIndex = html.IndexOf(stra, 0);

            while (true)
            {
                curIndex = html.IndexOf(str1, curIndex);
                if (curIndex == -1)
                    break;
                int startIndex = curIndex + str1.Length;

                curIndex = html.IndexOf(str2, startIndex);
                if (curIndex == -1)
                    break;
                int endIndex = curIndex;

                string StrTime = html.Substring(startIndex, endIndex - startIndex);
                string strHour = StrTime.Substring(0, 2);
                int Hour = Convert.ToInt32(strHour);
                if (Hour > 23)
                    break;
                curIndex += str2.Length;

                string strb = "td class=\"tdFormRow";
                string str3 = "\">";
                string str4 = "</td>";

                curIndex = html.IndexOf(strb, curIndex);
                curIndex = html.IndexOf(str3, curIndex);
                if (curIndex == -1)
                    break;
                startIndex = curIndex + str3.Length;

                curIndex = html.IndexOf(str4, startIndex);
                if (curIndex == -1)
                    break;
                endIndex = curIndex;
                curIndex += str4.Length;
                string StrTitle = html.Substring(startIndex, endIndex - startIndex);

                ProgramItem item = new ProgramItem();
                item.StartTime = item.GetDateTimeFromString(StrTime);
                item.Content = StrTitle;
                this._items.Add(item);
            }

        }
    }
}
